package de.mk.util;

import java.io.FileReader;
import java.io.IOException;

import org.apache.log4j.Logger;


public class FileUtil {
	
private final static Logger log = Logger.getLogger(FileUtil.class);
	
	/**
	 * 
	 * @param fileName
	 * @return
	 * @throws IOException
	 */
	public static String fileToString(String fileName) throws IOException{		
		FileReader reader = new FileReader(fileName);		
		String resultString = fileToString(reader);	
		reader.close();				
		return resultString;
	}
	
	/**
	 * 
	 * @param reader
	 * @return
	 * @throws IOException
	 */
	public static String fileToString(FileReader reader) throws IOException{		
		StringBuilder str = new StringBuilder();		
		int countBytes = 0;
		char[] bytesRead = new char[512];		
		
		while( (countBytes = reader.read(bytesRead)) > 0){
			str.append(bytesRead, 0, countBytes);
		}
					
		return str.toString();
	}


}
